use askama_axum::{IntoResponse, Response};
use axum::{extract::Request, middleware::Next, response::Redirect};
use tower_sessions::Session;

use crate::controllers::backend::AdminSession;


pub async fn auth_middleware(session: Session, request: Request, next: Next) -> Response {
    /*
    let path = request.uri().path().to_string();
    if path.starts_with("/login") {
        return next.run(request).await;
    }
    let response = next.run(request).await;
    let admin = session.get::<AdminSession>("admin").await;
    match admin {
        Ok(Some(_)) => {
            // 用户已登录
            response
        }
        Ok(None) => {
            // 用户未登录
            Redirect::to("/backend/login").into_response()
        }
        Err(_) => {
            // 错误
            Redirect::to("/backend/login").into_response()
        }
    }
      */
    next.run(request).await
}